package com.kedacom.freedomLabel.model.db.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.kedacom.freedomLabel.model.bean.Product;

import java.util.List;

/**
 * Author：李程
 * CreateTime：2020/2/26 22:53
 * E-mail：licheng@kedacom.com
 * Describe：
 */
@Dao
public interface ProductDao extends IDao<Product> {

    @Override
    @Query("SELECT COUNT(0) FROM ITEM")
    int count();

    @Override
    @Update
    void update(Product product);

    @Override
    @Insert(onConflict = OnConflictStrategy.FAIL)
    long save(Product product);

    @Override
    @Insert(onConflict = OnConflictStrategy.FAIL)
    long[] save(List<Product> products);

    @Override
    @Query("SELECT * FROM product ORDER BY createTime DESC")
    List<Product> get();

    @Override
    @Query("SELECT * FROM product WHERE name LIKE :keyword OR number LIKE :keyword ORDER BY createTime DESC")
    List<Product> get(String keyword);

    @Query("SELECT * FROM product WHERE number=:number")
    List<Product> getByNumber(String number);

    @Query("SELECT * FROM product WHERE name=:name")
    List<Product> getByProductName(String name);

    @Override
    @Query("SELECT * FROM product WHERE uuid =:uuid AND (name LIKE :keyword OR number LIKE :keyword) ORDER BY createTime DESC")
    List<Product> get(String uuid, String keyword);

    @Override
    @Delete
    void delete(Product item);

    @Override
    @Query("DELETE FROM product")
    void delete();

    @Override
    @Query("DELETE FROM product WHERE uuid =:uuid")
    void delete(String uuid);

}
